package app

import (
	"github.com/robfig/cron"
	"github.com/sirupsen/logrus"
	"simple-app/global"
	"simple-app/structs/tables"
)

func StartJob() {
	c := cron.New()
	if err := c.AddFunc(global.SysConf.Setting.StartTime, func() {
		global.StartBuying()
	}); err != nil {
		logrus.Error(err)
	}
	if err := c.AddFunc(global.SysConf.Setting.StartTime, func() {
		global.EndBuying()
	}); err != nil {
		logrus.Error(err)
	}
	c.Start()
}

func InitCatch() {
	var m tables.Setting
	err := global.DB.Model(&tables.Setting{}).Where("id = 1").First(&m).Error
	if err != nil {
		logrus.Error(err)
		return
	}
	global.UpdateSettingCatch(m)
}
